function setSelectList (data, val) {
  for (let item of data) {
    item.label = item[val.label]
    item.value = item[val.value]
  }
  return data
}
function setCascaderList (data, val) {
  for (let item of data) {
    item.label = item[val.mt][val.label]
    item.value = item[val.mt][val.value]
    item.children = item[val.child]
    if (item[val.child] && item[val.child].length) {
      setCascaderList(item[val.child], val)
    }
  }
}
const plusZero = (value) => {
  return value < 10 ? "0" + value : value;
}
function formatDate  (value, hasTime){
   if (!value) return "";
   if (typeof value === 'string') {
     value = value.replace(/\-/g, "/");
   }
   value = new Date(value);
   let result = "";
   let year = value.getFullYear();
   let month = value.getMonth() + 1;
   let day = value.getDate();
   month = plusZero(month);
   day = plusZero(day);
   result = year + "-" + month + "-" + day;
   if (hasTime) {
     let hour = value.getHours();
     let minute = value.getMinutes();
     let seconds = value.getSeconds();
     hour = plusZero(hour);
     minute = plusZero(minute);
     seconds = plusZero(seconds)
     result +=" " + hour + ":" + minute + ":" + seconds
   }
   return result
 }  
function getPuduct (data,val) {
  let newArray = [];
  for (let item of data) {
    for (let todo of item[val.child]) {
      newArray.push({
        productId: todo[val.getParam[0]],
        skuId: todo[val.getParam[1]],
        promotionPrice: todo[val.getParam[2]],
        isMustBuy: item[val.getParam[3]]
      })
    }
  }
  return newArray
}
function getGift (data,val) {
  let newArray = [];
  for (let item of data) {
    for (let todo of item[val.child]) {
      newArray.push({
        productId: todo[val.getParam[0]],
        skuId: todo[val.getParam[1]],
        quantity: todo[val.getParam[2]],
        returnPrice: todo[val.getParam[3]],
        productSn: todo[val.getParam[4]],
        skuSn: todo[val.getParam[5]],
        groups: '0'
      })
    }
  }
  return newArray
}
export {
  setSelectList,
  setCascaderList,
  formatDate,
  getPuduct,
  getGift
}